package com.yunhui.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunhui.entity.Merchant;
import com.yunhui.mapper.MerchantMapper;
import com.yunhui.service.MerchantService;

import com.yunhui.tool.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  商家的业务处理的层实现类
 * </p>
 *
 * @author WGH
 * @since 2019-12-09
 */
@Service
public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> implements MerchantService {

    @Autowired
    private MerchantMapper merchantMapper;


    /**
     * 注册
     * @param account
     * @param phone
     * @param eamil
     * @param password
     * @return
     */
    @Override
    public int insertMerchant(String account, String phone, String eamil, Date createDate, Integer status, String password) {
        return merchantMapper.insertMerchant(account,phone,eamil,createDate,status,password);
    }

    /**
     * 登录
     * @param username
     * @param password
     * @return
     */
    public Merchant userLogin(String username,String password){
        return merchantMapper.userlogin(username,password);
    }

    /**
     * 注册
     * @param merchant
     * @return
     */
    @Override
    public Result regist(Merchant merchant) {
        Result result = new Result();
        result.setSuccess(false);
        result.setDetail(null);
        try {
            Merchant existMerchant = merchantMapper.findUserByName(merchant.getAccount());
            if (existMerchant != null) {
                //如果用户名已存在
                result.setMsg("用户名已存在");
            } else {
                merchantMapper.regist(merchant);
                result.setMsg("注册成功");
                result.setSuccess(true);
                result.setDetail(merchant);
            }
        } catch (Exception e) {
            result.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return result;
    }


}
